<template>
  <div class='shop'>
    <!--面包屑-->
    <div class='crumbs'>
      <Crumbs :crumbs_title='crumbs_title'/>
    </div>
    <!--活动及品牌新闻列表-->
    <div class='shop-content'>
      <div class='shop-title'>
        <div class='ColNameBox'>
          <h1 class='h1'>Shop List</h1>
          <h2 class='h2'>店铺一览
            <span class='city'>
              <el-select v-model='params.code'
                         @change='regionChange'
                         placeholder='请选择'>
                <el-option
                  v-for='item in regions'
                  :key='item.code'
                  :label='item.region'
                  :value='item.code'>
                </el-option>
              </el-select>
            </span>
          </h2>
        </div>
      </div>
      <div class='shop-list'>
        <div class='shop1_1' v-for='(supplier, index) in this.supplierList' :key='index'>
          <div class='shopimg'>
            <a href='#'>
              <img :src='supplier.supplierPic'
                   width='216' height='155'/>
            </a>
          </div>
          <div class='shop1_2'>
            <div class='shopname'><a href='#'>{{ supplier.supplierName }}</a></div>
            <div class='shopweixin'>
              <a href='shop_info.html'>
                <img src='../../assets/images/weixin.jpg' width='54' height='18'/>
              </a>
            </div>
          </div>
          <div class='shopaddress'>{{ supplier.address }}</div>
          <div class='shoptel'>TEL:{{ supplier.phoneNumber }}</div>
          <div class='newsmore' style='width:216px; margin-top:0px; margin-top:15px;'>
            <a href='#'>
              <img src='../../assets/images/more.jpg' width='13' height='11'/>
              查看详细
            </a>
          </div>
        </div>
      </div>
    </div>
    <!--分页-->
    <!--分页-->
    <div class='pagination'>
      <el-pagination
        @size-change='sizeChangeHandle'
        @current-change='currentChangeHandle'
        :current-page='params.page'
        :page-sizes='[10, 20, 50, 100]'
        :page-size='params.limit'
        :total='this.totalCount'
        layout='total, sizes, prev, pager, next, jumper'
      ></el-pagination>
    </div>
  </div>
</template>

<script>
import Crumbs from '@/components/Crumbs'
import { getShops, getALlUseRegions } from '../../api/index'

export default {
  name: 'ShopList',
  data () {
    return {
      crumbs_title: '店铺一览',
      regions: [
        {
          region: '',
          code: 0
        }
      ],
      params: {
        page: 1, // 当前页
        limit: 10, // 一页获取几条数据
        code: 11 // 地区的编码
      },
      supplierList: [
        {
          address: '',
          bankAccount: '',
          bankName: '',
          code: 11,
          deleted: 1,
          linkMan: '',
          modifiedTime: '',
          phoneNumber: '',
          supplierCode: '',
          supplierId: 1,
          supplierName: '',
          supplierPic: '',
          supplierStatus: 1,
          supplierType: 2
        }
      ],
      totalCount: 100, // 数据库中一共有多少条数据
      totalPage: 10 // 数据库中按照limit的限制可以分为多少页
    }
  },
  components: {
    Crumbs
  },
  created () {
    this.init()
  },
  methods: {
    // 初始化店铺列表数据
    init () {
      this.getALlUseRegions()
    },
    getALlUseRegions () {
      getALlUseRegions().then(({ data }) => {
        this.regions = data
        if (this.regions.length > 0) {
          this.params.code = this.regions[0].code
        }
        this.getShopListData(this.params.code)
      }).catch(res => {
        console.log(res)
      })
    },
    getShopListData (code) {
      this.params.code = code
      getShops(this.params).then(({ data }) => {
        if (data.code === 0) {
          this.totalCount = data.page.totalCount
          this.totalPage = data.page.totalPage
          this.supplierList = data.page.list
        }
      }).catch(res => {
        console.log(res)
      })
    },
    // 每页数
    sizeChangeHandle (val) {
      this.params.limit = val
      this.params.page = 1
      this.getBrandList()
    },
    // 当前页
    currentChangeHandle (val) {
      this.params.page = val
      this.getBrandList()
    },
    regionChange (code) {
      this.getShopListData(code)
    }
  }
}
</script>

<style scoped lang='less'>
.shop {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  // shop-list
  .shop-content {
    width: 980px;
    margin: 0 auto;
    text-align: left;
    // 标题
    .shop-title {
      height: 66px;
      border-bottom: 2px solid #83B8D3;
      font-family: '微软雅黑';
      position: relative;
      margin-bottom: 20px;

      .ColNameBox {
        .h1 {
          font-weight: normal;
          font-size: 23px;
          color: #ABBDEB;
          text-transform: uppercase;
          height: 23px;
          line-height: 23px;
        }

        .h2 {
          font-weight: normal;
          font-size: 30px;
          color: #26355B;
          height: 30px;
          line-height: 30px;
          transform: translateY(-25px);

          .city {
            margin-left: 20px;
          }
        }
      }
    }

    .shop-list {
      .shop1_1 {
        width: 235px;
        height: 288px;
        overflow: hidden;
        border: 2px solid #e7e7e7;
        float: left;
        font-size: 12px;
        margin: 5px 8px 5px 0;
        background: #fff;
        box-sizing: border-box;
        padding: 7px;
        border-radius: 4px;
        color: #666666;
        line-height: 21px;

        .shop1_2 {
          padding-top: 15px;
          padding-right: 10px;
          padding-left: 2px;
          display: flex;
          justify-content: space-between;

          .shopname {
            a {
              text-decoration: none;
              color: #444444;
              font-size: 12px;
              font-weight: bold;
            }
          }
        }

        .shopaddress {
        }

        .shoptel {
          height: 21px;
        }

        .newsmore {
          margin-top: 5px;

          a {
            text-decoration: none;
            color: #91a3cf;
          }
        }
      }
    }
  }

  // 分页
  .pagination {
    width: 980px;
    height: 50px;
    margin-top: 50px;
  }
}
</style>
